package com.javasm.service.impl;

import com.javasm.dao.OrderDao;
import com.javasm.entity.Order;
import com.javasm.service.OrderService;
import com.javasm.utils.MyBatisHeapler;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class OrderServiceImpl implements OrderService {

    @Override
    public Integer countCustomerOrder(Order inputOrder) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        OrderDao mapper = sqlSession.getMapper(OrderDao.class);
        int total = mapper.countCustomerOrders(inputOrder);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return total;
    }

    @Override
    public List<Order> listCustomerOrders(Order inputOrder, Integer page, Integer pageSize) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        OrderDao mapper = sqlSession.getMapper(OrderDao.class);
        List<Order> orders = mapper.listCustomerOrders(inputOrder, (page - 1) * pageSize, pageSize);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return orders;
    }

}
